package com.study.java.jinjie.jihe.lianxi.wu;

import java.awt.*;
import java.util.Iterator;
import java.util.Set;



public class Score {
    private Set<Student> score1;

    public Score(Set<Student> score1) {
        this.score1 = score1;
    }

    public void PrintScore() {

        System.out.print("序号\t" + "  学号\t" + " 姓名\t" + " 成绩\n");
        System.out.println("-----------------------------------");
        Iterator<Student> iterator = score1.iterator();
        // {Student1, Student2, Student3, .... Studentn}
        int i = 1;
        while (iterator.hasNext()) {
                System.out.print(i++);
                Student student = iterator.next();
                System.out.print("  \t" + student.getNum() + " \t" +
                        student.getName() + "  \t" + student.getChengJI() + "\n");
        }
    }

    public void pingJun (){
        /*int pingjun = 0;
        int i =0;
        Iterator<Student> iterator = score1.iterator();
        while (iterator.hasNext()){
            i++;
            Student student = iterator.next();
           int  pingjun1 = student.getChengJI();
            pingjun =
        }*/
        float zong = 0f;
        int renShu = 0;
        float pingjun = 0f;
        Iterator<Student> iterator = score1.iterator();
        while (iterator.hasNext()){
            renShu++;
            Student student =iterator.next();
            int s = student.getChengJI();
            zong = zong+s;
        }
        pingjun = zong /renShu;

        System.out.println("平均分: "+pingjun);
    }


    public void max(){
        int max=0;
        String student1 = " ";
        Iterator<Student> iterator = score1.iterator();
        while (iterator.hasNext()){
            Student student= iterator.next();
            int s = student.getChengJI();
            if (s>max){
                max = s;
                student1 = student.getName();
            }

        }
        System.out.println( student1 + "最高成绩:" + max);
    }








}
